import 'package:bxultimate/data/request/organization_request.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'state.dart';

class OrganizationApproveDetailController extends GetxController {
  final OrganizationApproveDetailState state = OrganizationApproveDetailState();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    getData();
  }

  getData() async {
    state.approve =
        await OrganizationRequest.getAdjustRecordEvents(Get.arguments);
  }

  void handleApproveClick(int status) async {
    var id = Get.arguments;
    var editor = TextEditingController();
    if (status == 2) {
      showGeneralDialog(
        context: Get.context!,
        pageBuilder: (BuildContext buildContext, Animation<double> animation,
            Animation<double> secondaryAnimation) {
          return TDInputDialog(
            textEditingController: editor,
            title: '请输入拒绝原因',
            rightBtn: TDDialogButtonOptions(
                title: '确定',
                action: () async {
                  await OrganizationRequest.submitApprove({
                    "id": id,
                    "rejectReason": editor.text,
                    "status": status //1同意  2拒绝
                  });
                  SmartDialog.showNotify(
                      msg: '操作成功', notifyType: NotifyType.success);
                  Get.back();
                }),
          );
        },
      );
    } else {
      await OrganizationRequest.submitApprove({
        "id": id,
        "status": status //1同意  2拒绝
      });
      SmartDialog.showNotify(msg: '操作成功', notifyType: NotifyType.success);
      Get.back();
    }
  }
}
